package com.pybox.api;

import com.pybox.service.TEventCategroyService;
import com.pybox.dto.TEventCategroyDto;

import com.pybox.dto.Result;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.*;

/**
* 描述：TEventCategroy Api
* @author wuyingkai
* @date 2018-09-15
*/

@Slf4j
@RequestMapping("/TEventCategroy")
@Api(tags = "TEventCategroy管理接口", description = "TEventCategroy管理接口")
@RestController
public class TEventCategroyApi {

    @Autowired
    private TEventCategroyService service;

    @ApiOperation(value = "创建TEventCategroy", notes = "创建TEventCategroy")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public Result<Boolean> save(@RequestBody TEventCategroyDto dto) {
        service.create(dto);
        return Result.ok(true);
    }

    @ApiOperation(value = "删除TEventCategroy", notes = "删除TEventCategroy")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
    @ApiImplicitParam(name = "id", value = "TEventCategroy id", dataType = "String", paramType = "path")
    public Result<Boolean> delete(@PathVariable("id") Integer id) {
        service.delete(id);
        return Result.ok(true);
    }

    @ApiOperation(value = "更新TEventCategroy", notes = "更新TEventCategroy")
    @RequestMapping(value = "/update/{id}", method = RequestMethod.PUT)
    @ApiImplicitParam(name = "id", value = "TEventCategroy id", dataType = "String", paramType = "path")
    public Result<Boolean> update(@PathVariable("id") Integer id, @RequestBody TEventCategroyDto dto) {
        service.update(id, dto);
        return Result.ok(true);
    }

    @ApiOperation(value = "查询TEventCategroy", notes = "查询TEventCategroy")
    @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
    @ApiImplicitParam(name = "id", value = "TEventCategroy id", dataType = "String", paramType = "path")
    public Result<TEventCategroyDto> detail(@PathVariable("id") Integer id) {

        return Result.ok(service.detail(id));
    }

    @ApiOperation(value = "分页查询TEventCategroy", notes = "分页查询TEventCategroy")
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    @ApiImplicitParams({
           @ApiImplicitParam(name = "id", value = "id", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "name", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "event", value = "event", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "comments", value = "comments", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "ctime", value = "ctime", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "utime", value = "utime", dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "pageNo", value = "pageNo", dataType = "int", paramType = "query"),
        @ApiImplicitParam(name = "pageSize", value = "pageSize", dataType = "int", paramType = "query")
    })
    public Result<Page<TEventCategroyDto>> page(
                        @RequestParam(required = false) Integer id,
                        @RequestParam(required = false) String name,
                        @RequestParam(required = false) String comments,
                        @RequestParam(required = false) String envent,
                        @RequestParam(required = false) String ctime,
                        @RequestParam(required = false) String utime,
                    @RequestParam(required = true) Integer pageNo,
                    @RequestParam(required = true) Integer pageSize) {

        Map<String, String> params = new HashMap<>();

                params.put("name",name);
                params.put("event",envent);
                params.put("comments",comments);
                params.put("ctime",ctime);
                params.put("utime",utime);
        return Result.ok(service.page(pageNo, pageSize, params));
    }
}